package com.tgy.hash.type;

/**
 * @Author: tgy
 * @Date: 2020-09-24 10:05
 */
public class StringHash {

    public static void main(String[] args) {


        String name = "zhangsan";


        int hashCode = name.hashCode();

        int customHashCode = 0;

        for (int i = 0; i < name.length(); i++) {

            char locChar = name.charAt(i);
            customHashCode = 31 * customHashCode + locChar;
            System.out.println(customHashCode);
        }
//        31 * n
//        n ^ 5  - n
        System.out.println(hashCode);
        System.out.println(customHashCode);
    }
}
